home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr26 / netprog.zip / NETPROG.TAR / tftp / cmdgetput.c < prev    next >
C/C++ Source or Header  |  1989-12-17  |  2KB  |  79 lines

  1. /*
  2.  * File get/put processing.
  3.  *
  4.  * This is the way the client side gets started - either the user
  5.  * wants to get a file (generates a RRQ command to the server)
  6.  * or the user wants to put a file (generates a WRQ command to the
  7.  * server).  Once either the RRQ or the WRQ command is sent,
  8.  * the finite state machine takes over the transmission.
  9.  */
  10.  
  11. #include    "defs.h"
  12.  
  13. /*
  14.  * Execute a get command - read a remote file and store on the local system.
  15.  */
  16.  
  17. do_get(remfname, locfname)
  18. char    *remfname;
  19. char    *locfname;
  20. {
  21.     if ( (localfp = file_open(locfname, "w", 1)) == NULL) {
  22.         err_ret("can't fopen %s for writing", locfname);
  23.         return;
  24.     }
  25.  
  26.     if (net_open(hostname, TFTP_SERVICE, port) < 0)
  27.         return;
  28.  
  29.     totnbytes = 0;
  30.     t_start();        /* start timer for statistics */
  31.  
  32.     send_RQ(OP_RRQ, remfname, modetype);
  33.  
  34.     fsm_loop(OP_RRQ);
  35.  
  36.     t_stop();        /* stop timer for statistics */
  37.  
  38.     net_close();
  39.  
  40.     file_close(localfp);
  41.  
  42.     printf("Received %ld bytes in %.1f seconds\n", totnbytes, t_getrtime());
  43.                 /* print stastics */
  44. }
  45.  
  46. /*
  47.  * Execute a put command - send a local file to the remote system.
  48.  */
  49.  
  50. do_put(remfname, locfname)
  51. char    *remfname;
  52. char    *locfname;
  53. {
  54.     if ( (localfp = file_open(locfname, "r", 0)) == NULL) {
  55.         err_ret("can't fopen %s for reading", locfname);
  56.         return;
  57.     }
  58.  
  59.     if (net_open(hostname, TFTP_SERVICE, port) < 0)
  60.         return;
  61.  
  62.     totnbytes = 0;
  63.     t_start();        /* start timer for statistics */
  64.  
  65.     lastsend = MAXDATA;
  66.     send_RQ(OP_WRQ, remfname, modetype);
  67.  
  68.     fsm_loop(OP_WRQ);
  69.  
  70.     t_stop();        /* stop timer for statistics */
  71.  
  72.     net_close();
  73.  
  74.     file_close(localfp);
  75.  
  76.     printf("Sent %ld bytes in %.1f seconds\n", totnbytes, t_getrtime());
  77.                 /* print stastics */
  78. }
  79.